import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttermodule/utils/screen.dart';

/**
 *点餐的分组lable
 */
class MealLabelWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(dpWidth(30), dpHeight(10), dpWidth(20), 0),
      child: Flex(
        direction: Axis.horizontal,
        children: <Widget>[
          Expanded(
            child: Text(
              "午餐",
              style: TextStyle(
                  fontSize: spFont(28),
                  fontWeight: FontWeight.bold,
                  color: Color.fromARGB(255, 51, 51, 51)),
            ),
            flex: 1,
          ),
          Expanded(
              flex: 0,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Image.asset(
                    "assets/meal/images/list_shijian.png",
                    width: dpHeight(20),
                    height: dpHeight(20),
                  ),
                  Padding(
                    padding: EdgeInsets.only(bottom: 2, left: 4),
                    child: Text(
                      "用餐时间:2017-03-03 星期五",
                      textAlign: TextAlign.center,
                      style: TextStyle(
                          color: Color.fromARGB(255, 153, 153, 153),
                          fontSize: spFont(20)),
                    ),
                  )
                ],
              ))
        ],
      ),
      decoration: BoxDecoration(
          border: Border(
              top: BorderSide(
                  color: Color.fromARGB(153, 238, 238, 238),
                  width: dpHeight(20),
                  style: BorderStyle.solid))),
    );
  }
}

/**
 * 点餐的item
 */
class MealItemWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MealItemState();
  }
}

class _MealItemState extends State<MealItemWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          Flex(
            direction: Axis.horizontal,
            children: <Widget>[
              Expanded(
                  flex: 0,
                  child: Padding(
                    padding: EdgeInsets.only(
                        left: dpWidth(30),
                        top: dpHeight(50),
                        right: dpWidth(26),
                        bottom: dpHeight(50)),
                    child: Stack(
                      alignment: Alignment.center,
                      children: <Widget>[
                        Image.asset(
                          "assets/meal/images/img_dc_sx.png",
                          width: dpWidth(90),
                          height: dpWidth(90),
                        ),
                        Text(
                          '米',
                          style: TextStyle(
                              fontSize: spFont(40),
                              fontWeight: FontWeight.bold,
                              color: Colors.white),
                        )
                      ],
                    ),
                  )),
              Expanded(
                  flex: 1,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          Text(
                            '元气满满',
                            style: TextStyle(
                                fontSize: spFont(34),
                                fontWeight: FontWeight.bold),
                          ),
                          Container(
                            alignment: Alignment.center,
                            margin: EdgeInsets.only(left: dpWidth(12)),
                            padding: EdgeInsets.only(
                                left: dpWidth(13),
                                top: dpHeight(2),
                                right: dpWidth(13),
                                bottom: dpHeight(2)),
                            decoration: BoxDecoration(
                                color: Color.fromARGB(255, 247, 247, 247),
                                borderRadius:
                                    BorderRadius.circular(dpHeight(20))),
                            child: Text(
                              '两荤一素',
                              style: TextStyle(
                                  fontSize: spFont(24),
                                  color: Color.fromARGB(255, 153, 153, 153)),
                            ),
                          )
                        ],
                      ),
                      Container(
                        padding: EdgeInsets.only(top: dpHeight(1)),
                        child: Text(
                          '干锅鸡  青笋木耳肉片  鱼香茄子',
                          style: TextStyle(fontSize: spFont(28)),
                        ),
                      )
                    ],
                  )),
              Expanded(
                  flex: 0,
                  child: Container(
                    margin: EdgeInsets.only(right: dpWidth(30)),
                    child: Image.asset(
                      'assets/meal/images/btn_s_xuanzhe.png',
                      width: dpWidth(36),
                      height: dpWidth(36),
                    ),
                  ))
            ],
          ),
          Container(
            height: 1,
            margin: EdgeInsets.only(left: dpWidth(136), right: dpWidth(30)),
            decoration:
                BoxDecoration(color: Color.fromARGB(255, 238, 238, 238)),
          )
        ],
      ),
    );
  }
}

/**
 * 点餐记录的item
 */
class MealRecordItemWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MealRecordItemState();
  }
}

class _MealRecordItemState extends State<MealRecordItemWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
        color: Color.fromARGB(255, 255, 255, 255),
        padding: EdgeInsets.fromLTRB(
            dpWidth(30), dpHeight(39), dpWidth(30), dpHeight(21)),
        child: Column(
          children: <Widget>[
            Flex(
              direction: Axis.horizontal,
              children: <Widget>[
                Expanded(
                  child: Text(
                    "午餐",
                    style: TextStyle(
                        fontSize: spFont(32),
                        fontWeight: FontWeight.bold,
                        color: Color.fromARGB(255, 51, 51, 51)),
                  ),
                  flex: 1,
                ),
                Expanded(
                    flex: 0,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Image.asset(
                          "assets/meal/images/list_shijian.png",
                          width: dpHeight(20),
                          height: dpHeight(20),
                        ),
                        Padding(
                          padding: EdgeInsets.only(bottom: 2, left: 4),
                          child: Text(
                            "用餐时间：12月18日 星期四",
                            textAlign: TextAlign.center,
                            style: TextStyle(
                                color: Color.fromARGB(255, 153, 153, 153),
                                fontSize: spFont(24)),
                          ),
                        )
                      ],
                    ))
              ],
            ),
            Container(
              child: Column(
                children: <Widget>[
                  Flex(
                    direction: Axis.horizontal,
                    children: <Widget>[
                      Expanded(
                          flex: 0,
                          child: Padding(
                            padding: EdgeInsets.only(
                                left: dpWidth(0),
                                top: dpHeight(50),
                                right: dpWidth(24),
                                bottom: dpHeight(50)),
                            child: Stack(
                              alignment: Alignment.center,
                              children: <Widget>[
                                Image.asset(
                                  "assets/meal/images/img_dc_sx.png",
                                  width: dpWidth(90),
                                  height: dpWidth(90),
                                ),
                                Text(
                                  '米',
                                  style: TextStyle(
                                      fontSize: spFont(40),
                                      fontWeight: FontWeight.bold,
                                      color: Colors.white),
                                )
                              ],
                            ),
                          )),
                      Expanded(
                          flex: 1,
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text(
                                    '元气满满',
                                    style: TextStyle(
                                        fontSize: spFont(34),
                                        fontWeight: FontWeight.bold),
                                  ),
                                  Container(
                                    alignment: Alignment.center,
                                    margin: EdgeInsets.only(left: dpWidth(12)),
                                    padding: EdgeInsets.only(
                                        left: dpWidth(13),
                                        top: dpHeight(2),
                                        right: dpWidth(13),
                                        bottom: dpHeight(2)),
                                    decoration: BoxDecoration(
                                        color:
                                            Color.fromARGB(255, 247, 247, 247),
                                        borderRadius: BorderRadius.circular(
                                            dpHeight(20))),
                                    child: Text(
                                      '两荤一素',
                                      style: TextStyle(
                                          fontSize: spFont(24),
                                          color: Color.fromARGB(
                                              255, 153, 153, 153)),
                                    ),
                                  )
                                ],
                              ),
                              Container(
                                padding: EdgeInsets.only(top: dpHeight(1)),
                                child: Text(
                                  '干锅鸡  青笋木耳肉片  鱼香茄子',
                                  style: TextStyle(fontSize: spFont(28)),
                                ),
                              )
                            ],
                          )),
                    ],
                  ),
                  Container(
                    margin: EdgeInsets.only(bottom: dpHeight(20)),
                    height: 1,
                    decoration: BoxDecoration(
                        color: Color.fromARGB(255, 238, 238, 238)),
                  ),
                  Flex(
                    direction: Axis.horizontal,
                    children: <Widget>[
                      Expanded(
                          child: Container(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: <Widget>[
                                Image.asset(
                                  "assets/meal/images/list_shijian.png",
                                  width: dpHeight(20),
                                  height: dpHeight(20),
                                ),
                                Padding(
                                  padding: EdgeInsets.only(left: dpWidth(4)),
                                  child: Text(
                                    "2018年12月18日 13:51",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                        color:
                                            Color.fromARGB(255, 153, 153, 153),
                                        fontSize: spFont(24)),
                                  ),
                                )
                              ],
                            ),
                            Container(
                              margin: EdgeInsets.only(top: dpHeight(4)),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Image.asset(
                                    "assets/meal/images/list_shijian.png",
                                    width: dpHeight(20),
                                    height: dpHeight(20),
                                  ),
                                  Padding(
                                    padding: EdgeInsets.only(left: dpWidth(4)),
                                    child: Text(
                                      "成都-政府服务中心",
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Color.fromARGB(
                                              255, 153, 153, 153),
                                          fontSize: spFont(24)),
                                    ),
                                  )
                                ],
                              ),
                            )
                          ],
                        ),
                      )),
                      Expanded(
                          flex: 0,
                          child: Container(
                            alignment: Alignment.center,
                            child: FlatButton(
                              color: Color.fromARGB(255, 16, 187, 184),
                              onPressed: () {},
                              child: Text(
                                '取消订餐',
                                style: TextStyle(
                                    fontSize: spFont(28), color: Colors.white),
                              ),
                              shape: RoundedRectangleBorder(
                                  borderRadius:
                                      BorderRadius.circular(dpHeight(30))),
                            ),
                          ))
                    ],
                  )
                ],
              ),
            )
          ],
        ));
  }
}

/**
 * 点餐成功的弹窗
 */
class MealSucceedDialog extends Dialog {
  @override
  Widget build(BuildContext context) {
    return new Material(
      //创建透明层
      type: MaterialType.transparency, //透明类型
      child: Center(
        //保证控件居中效果
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Container(
              width: dpWidth(450),
              child: Stack(
                alignment: Alignment.bottomCenter,
                children: <Widget>[
                  Image.asset("assets/meal/images/img_dc_jccg.png"),
                  Container(
                    child: FlatButton(
                      onPressed: () {
                        Navigator.pop(context);
                        Navigator.pushNamed(context, "/order_meal_record_page",
                            arguments: "");
                      },
                      color: Color.fromARGB(255, 16, 187, 184),
                      child: Text(
                        "查看详情",
                        style: TextStyle(
                            fontSize: spFont(28), color: Colors.white),
                      ),
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(dpHeight(30))),
                    ),
                    margin: EdgeInsets.only(bottom: dpHeight(20)),
                  )
                ],
              ),
            ),
            Container(
                margin: EdgeInsets.only(top: dpHeight(70)),
                child: InkWell(
                  child: Image.asset(
                    "assets/meal/images/btn_dc_guanbix.png",
                    height: dpWidth(80),
                    width: dpWidth(80),
                  ),
                  onTap: () {
                    Navigator.pop(context);
                  },
                ))
          ],
        ),
      ),
    );
  }
}

typedef localPopupCall = void Function(String local);

/**
 * 选择点餐地址的popup
 */
void showMealLocalPopup(BuildContext context, localPopupCall callback) {
  var localArr = [
    "郑州分公司",
    "成都-桃园3楼",
    "成都-桃园26楼",
    "成都-保利中心6楼",
    "郑州分公司",
    "成都-桃园3楼",
    "成都-桃园26楼",
    "成都-保利中心6楼"
  ];
  showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return Stack(
          children: <Widget>[
            Container(
              height: dpHeight(25),
              width: double.infinity,
              color: Colors.black54,
            ),
            Container(
                height: dpHeight(500),
                width: double.infinity,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(dpHeight(10)),
                        topRight: Radius.circular(dpHeight(10))),
                    color: Colors.white),
                child: Column(
                  children: <Widget>[
                    Padding(
                      padding: EdgeInsets.only(
                          top: dpHeight(20), bottom: dpHeight(20)),
                      child: Text(
                        "选择订餐区域",
                        style:
                            TextStyle(color: Colors.blue, fontSize: spFont(34)),
                      ),
                    ),
                    Container(
                        color: Color.fromARGB(255, 203, 203, 203),
                        height: dpHeight(1)),
                    Expanded(
                      child: ListView.separated(
                        itemCount: localArr.length,
                        itemBuilder: (BuildContext context, int position) {
                          return InkWell(
                              child: Padding(
                                padding: EdgeInsets.only(
                                    top: dpHeight(20), bottom: dpHeight(20)),
                                child: Text(
                                  localArr[position],
                                  textAlign: TextAlign.center,
                                  style: TextStyle(
                                      color: Colors.black,
                                      fontSize: spFont(28)),
                                ),
                              ),
                              onTap: () {
                                Navigator.pop(context);
                                callback(localArr[position]);
                              });
                        },
                        separatorBuilder: (BuildContext context, int position) {
                          return Divider(
                              height: dpHeight(1),
                              color: Color.fromARGB(255, 203, 203, 203));
                        },
                      ),
                    )
                  ],
                ))
          ],
        );
      });
}
